# -*- coding=utf-8-*-
"""
@File:memory_selection
@Author:Created by Han X.Y
@Date:on 2021/7/8 8:58 
"""

"""
相邻元素交换顺序

"""


def swapPairs(List):
    """
    相邻元素交换位置
    """
    if len(List) == 1:
        return List
    new_List = List.copy()
    for i in range(len(List)):
        if i % 2 == 0:
            new_List[i], new_List[i + 1] = new_List[i + 1], new_List[i]
    return new_List


"""
交换k个相邻元素

"""


def swapPairs_k(List, k):
    """
    相邻元素交换位置
    """
    if len(List) < k:
        return List
    new_List = List.copy()
    for i in range(len(List)):
        if i % k == 0:
            new_List[i:(i + k)] = new_List[i:(i + k)][::-1]
    return new_List